package com.ssy.lingxi.message.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.MessageIdRequest;
import com.ssy.lingxi.message.api.vo.response.MessageUnreadCountResponse;
import com.ssy.lingxi.message.enums.MessageBusinessTypeEnum;
import com.ssy.lingxi.message.model.vo.MobileMessageDetailResponse;
import com.ssy.lingxi.message.model.vo.MobileMessageResponse;
import com.ssy.lingxi.message.service.IMemberMessageService;
import com.ssy.lingxi.message.service.IMobileMemberMessageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @menu App - 系统消息
 * @author yzc
 * @version 2.0.0
 * @date 2020/10/27
 */
@RestController
@RequestMapping("/message/mobile/message/member")
public class MobileMemberMessageController extends BaseController {

    @Resource
    private IMobileMemberMessageService mobileMemberMessageService;
    @Resource
    private IMemberMessageService memberMessageService;

    /**
     * 系统消息统计
     * @return 返回结果
     */
    @GetMapping("/unread/count")
    public Wrapper<MessageUnreadCountResponse> unreadCount() {
        UserLoginCacheDTO loginUser = getSysUser();
        return mobileMemberMessageService.unreadCount(loginUser);
    }

    /**
     * 系统公告
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/system/page")
    public Wrapper<PageData<MobileMessageResponse>> systemPage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        return mobileMemberMessageService.pagePlatformMessage(request, loginUser);
    }

    /**
     * 交易通知
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/trade/page")
    public Wrapper<PageData<MobileMessageResponse>> tradePage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.IQ, MessageBusinessTypeEnum.ORDER);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 采购通知
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/purchase/page")
    public Wrapper<PageData<MobileMessageResponse>> purchasePage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.DQ);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 采购通知
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/afterSale/page")
    public Wrapper<PageData<MobileMessageResponse>> afterSalePage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.AFTER_SALE);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 资金通知
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/capital/page")
    public Wrapper<PageData<MobileMessageResponse>> capitalPage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.CAPITAL);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 促销优惠
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/marketing/page")
    public Wrapper<PageData<MobileMessageResponse>> marketingPage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();
        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.MARKETING);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 消息提醒
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/notice/page")
    public Wrapper<PageData<MobileMessageResponse>> noticePage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();

        List<MessageBusinessTypeEnum> businessTypeEnumList = Arrays.asList(MessageBusinessTypeEnum.MEMBER);
        return mobileMemberMessageService.pageBusinessMessage(request, loginUser, businessTypeEnumList);
    }

    /**
     * 消息详情
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping("/read")
    public Wrapper<Void> updateReadMemberMessage(@Validated @RequestBody MessageIdRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return memberMessageService.updateReadMemberMessage(request, loginUser);
    }

    /**
     * 消息详情
     * @param id 消息id
     * @return 返回结果
     */
    @GetMapping("/get")
    public Wrapper<MobileMessageDetailResponse> getMemberMessage(@RequestParam(name = "id") Long id) {
        UserLoginCacheDTO loginUser = getSysUser();
        return mobileMemberMessageService.getMemberMessage(id, loginUser);
    }

    /**
     * 设置全部已读消息
     * @return 返回结果
     */
    @PostMapping("/readAll")
    public Wrapper<Void> updateAllReadMemberMessage() {
        UserLoginCacheDTO loginUser = getSysUser();
        return memberMessageService.updateAllReadMemberMessage(loginUser);
    }

}
